﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Management/Manage.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    AddArticle
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(document).ready(function() {

        $("a").removeClass("current");
        $("#articles").addClass("current");
        var e = jQuery.Event("click");
        $("#articles").trigger(e);
        $("#add-articles").addClass("current");

    });
</script>
    <div class="content-box">
        <!-- Start Content Box -->
        <div class="content-box-header">
            <h3>
                Add Article</h3>
            
            <div class="clear">
            </div>
        </div>
        <!-- End .content-box-header -->
        <div class="content-box-content">
            <div class="tab-content default-tab" id="tab1">
        
    
   <form action="/Management/AddArticle" name="form1" method="post">
    <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
								
			<p>
				<label>Title</label>
					<input class="text-input small-input" type="text" id="name" name="name" /> 
					
					<br /><small>The title of the article</small>
			</p>
			<p>
				<label>Meta Description</label>
					<input class="text-input small-input" type="text" id="Text1" name="desc" /> 
					
					<br /><small>The description of the article</small>
			</p>
			<p>
				<label>Meta Keywords</label>
					<input class="text-input small-input" type="text" id="Text2" name="keywords" /> 
					
					<br /><small>The keywords for the article</small>
			</p>
            
            <p>
				<label>Body</label>
				<textarea class="text-input textarea wysiwyg" id="body" name="body" cols="79" rows="15"></textarea>
			</p>
             <p>
				<label>Menu Item</label>              
				<select name="menuid" class="small-input">
                <% foreach(var m in (IList<CSI.Directory.Core.Model.Menu>)ViewData["Menus"]){%>
                    <option value="<%=m.Id %>"><%=m.Title %></option>                    
                <%} %>
                </select>
             </p>
             <p>
             <label>Featured</label>
                <input type="checkbox" name="featured" id="featured"/>   
             </p>
             <input type="button" onclick="return DoAjaxSubmit(this);" value="Add" class="button" />
             <div id="results"></div>
            </fieldset>
   </form>
    </div>
        </div>
    </div>
    
    <script type="text/javascript">
        function DoAjaxSubmit(btnClicked) {
            var form = $(btnClicked).parents('form');
            if ($("#name").val() == "" || $("#body").val() == "") {
                $("#results").html("Please complete all fields").addClass("red");
                return false;
            }
            else {
                $("#results").html("");
                $.ajax({
                    type: "POST",
                    url: form.attr('action'), //'<%=ResolveUrl("~/register/go") %>',
                    data: form.serialize(),
                    error: function(xhr, status, error) {
                    },
                    success: function(response) {
                        if (response != null) {
                            if (!response.Successful) {
                                $("#results").html("An error occurred: " + response.Exception).addClass("red");
                                return false;
                            }
                            else {
                                $("#results").html("Article added").addClass("green");
                                document.form1.reset();
                            }
                        }
                    }
                });
            }
            return false;
        }
    </script>

</asp:Content>
